import Vue from 'vue'
window.Vue = Vue
import request from '@/utils/request'
import {
  download,
  getDownload
} from '@/utils/request'
console.log(getDownload)
import Cookies from 'js-cookie'
// 是否启用多语言
var enableMultiLanguage = window.g.multiLanguage || false
if (!enableMultiLanguage) {
  localStorage.removeItem('language')
}
var language = localStorage.getItem('language') || 'zh-CN'

import 'normalize.css/normalize.css' // a modern alternative to CSS resets

import Element from 'element-ui'
import localeEN from 'element-ui/lib/locale/lang/en'
import localeZHCN from 'element-ui/lib/locale/lang/zh-CN'
var eleLocale = language === 'en-US' ? localeEN : localeZHCN
import 'element-ui/lib/theme-chalk/index.css'
import './styles/element-variables.scss'

import '@/utils/directives.js'
import '@/utils/prototype.js'

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'
import VCharts from 'v-charts'

import './icons' // icon
import './permission' // permission control

import * as filters from './filters' // global filters
import layout from '@/layout/index'
import 'viewerjs/dist/viewer.css'
import Viewer from 'v-viewer'
Vue.use(Viewer, {
  defaultOptions: {
    zIndex: 9999
  }
})
import Codemirror from 'vue-codemirror'
import 'codemirror/lib/codemirror.css'
Vue.use(Codemirror
  /* {
  options: { theme: 'base16-dark', ... },
  events: ['scroll', ...]
} */
)
Vue.use(VCharts)

// jsplumb
import 'jsplumb/dist/js/jsplumb.min.js'
import 'jsplumb/css/jsplumbtoolkit-defaults.css'
import ContextMenu from '@/plugins/ContextMenu'
Vue.use(ContextMenu)

import localDisplayTypes from '@/extends/displayType/index.js'
Object.keys(localDisplayTypes).forEach(componentName => {
  Vue.component(componentName, localDisplayTypes[componentName].component)
})

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
const loadView = (view) => { // 路由懒加载
  return (resolve) => require([`@/views/${view}`], resolve)
}
import {
  getAppId,
  getBaseApi,
  $tra
} from '@/utils/index'
// 引入store
import Qibao from './admin'
Vue.prototype.$tra = $tra
Vue.use(Qibao, {
  router: router,
  store: store,
  request: request,
  download: download,
  getDownload: getDownload,
  layout: layout,
  utils: {
    loadView,
    getAppId,
    getBaseApi
  }
})

try {
  window.$CodeSource = JSON.parse(localStorage.$CodeSource)
} catch (e) {
  window.$CodeSource = []
}

Vue.use(Element, {
  size: Cookies.get('size') || 'medium',
  locale: eleLocale
})

// register global utility filters
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

Vue.config.productionTip = false

window.zoom = 1
var zoom = window.devicePixelRatio || window.screen.deviceXDPI / window.screen.logicalXDPI
console.log(zoom)
if (!!window.ActiveXObject || 'ActiveXObject' in window) {
  if (zoom != 1 && zoom != 2 && zoom != 3) {
    alert('系统检测到您的设备对显示进行放大，可能导致页面显示不全,请调整后打开/或使用其他浏览器！')
  }
}

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
